@using BlazorDatasheet.Util
@using BlazorDatasheet.Core.Interfaces
@using BlazorDatasheet.Core.Data
@using BlazorDatasheet.Core.Edit
@inherits BaseEditor

<input
    type="date"
    class="date-input"
    @bind="CurrentDateTime"
    @bind:event="oninput"
    style="@CssUtil.GetStyledInput(Cell); width: 100%;"
    @ref="InputRef"/>

@code {

    private IReadOnlyCell Cell { get; set; }
    private DateTime _dateTime;

    private DateTime? CurrentDateTime
    {
        get
        {
            var parsed = DateTime.TryParse(CurrentValue, out var parsedDateTime);
            if (parsed)
                return parsedDateTime;
            else
                return null;
        }
        set
        {
            if (value.HasValue)
                this.OnValueChanged.InvokeAsync(value.ToString());
        }
    }

    public override void BeforeEdit(IReadOnlyCell cell, Sheet sheet)
    {
        Cell = cell;
    }

    public override void BeginEdit(EditEntryMode entryMode, string? editValue, string key)
    {
    /*var canParse = DateTime.TryParse(editValue?.ToString(), out var parsedDateTime);
        if (canParse)
        {
            CurrentDateTime = parsedDateTime;
        }
        else
        {
            CurrentDateTime = DateTime.Now;
        }*/
    }

}